<template>
	<view class="container">
		<view class="list-cell b-b m-t" @click="navTo('../../pagesU/user/profile')" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">个人资料</text>
			<text class="cell-more yticon icon-you"></text>
		</view>
		<view class="list-cell b-b" @click="navTo('../../pagesU/address/address')" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">收货地址</text>
			<text class="cell-more yticon icon-you"></text>
		</view>
		<!-- <view class="list-cell" @click="navTo('/pages/set/certification')" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">实名认证</text>
			<text class="cell-more yticon icon-you"></text>
		</view> -->

		<view class="list-cell" @click="navTo('./addPassword')" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">设置支付密码</text>
			<text class="cell-more yticon icon-you"></text>
		</view>
		<view class="list-cell m-t">
			<text class="cell-tit">消息推送</text>
			<switch checked color="#fa436a" @change="switchChange" />
		</view>
		<view class="list-cell b-b" @click="update" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">更新邀请海报</text>
			<!-- <text class="cell-more yticon icon-you"></text> -->
		</view>
		<view class="list-cell">
			<text class="cell-tit">检查更新</text>
			<text class="cell-tip">当前版本: {{version}}</text>
			<text class="cell-more yticon icon-you"></text>
		</view>
		<view class="list-cell log-out-btn" @click="toLogout">
			<text class="cell-tit">退出登录</text>
		</view>
		<mallplusCopyright></mallplusCopyright>
	</view>
</template>

<script>
	import mallplusCopyright from '@/components/mall-copyright/mallplusCopyright.vue';
	import Api from '@/common/api';
	import {
		mapMutations
	} from 'vuex';
	export default {
		components: {
			mallplusCopyright
		},
		data() {
			return {
				sysInfo: '',
				version: ''
			};
		},
		onLoad() {
			this.sysInfo = this.$db.get('sysInfo');
			//#ifdef APP-PLUS
			this.getVersion()
			// #endif
		},
		methods: {
			...mapMutations(['logout']),
			// 版本号
			getVersion() {
				let This = this;
				plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {
					This.version = widgetInfo.version;
				})
			},
			// 更新二维码
			async update(){
				let userinfo = uni.getStorageSync('userInfos');
				let params = {
					memberId:userinfo.id
				}
				let res = await Api.apiCall('', 'single/user/updateQrCode', params);
				if(res == true){
					uni.showToast({
						icon:'none',
						title:'更新成功！'
					})
				}else{
					uni.showToast({
						icon: 'none',
						title:'二维码更新失败！'
					})
				}
			},
			navTo(url) {
				uni.navigateTo({
					url: url
				});
				// this.$api.msg(`跳转到${url}`);
			},
			//退出登录
			toLogout() {
				uni.showModal({
					content: '确定要退出登录么',
					success: e => {
						if (e.confirm) {
							this.logout();
							this.$db.del('userInfos')
							this.$db.del('token')
							Api.apiCall('post', Api.index.logout, {});
							setTimeout(() => {
								uni.navigateBack();
							}, 200);
						}
					}
				});
			},
			//switch
			switchChange(e) {
				let statusTip = e.detail.value ? '打开' : '关闭';
				this.$api.msg(`${statusTip}消息推送`);
			}
		}
	};
</script>

<style lang="scss">
	page {
		background: $page-color-base;
	}

	.list-cell {
		display: flex;
		align-items: baseline;
		padding: 20upx;
		line-height: 60upx;
		position: relative;
		background: #fff;
		justify-content: center;

		&.log-out-btn {
			margin-top: 40upx;
			border-radius: 50upx;
			width: 95%;
			margin-left: 2.5%;
			background: $uni-color-primary;

			.cell-tit {
				color: #FFFFFF;
				text-align: center;
				margin-right: 0;
			}
		}

		&.cell-hover {
			background: #fafafa;
		}

		&.b-b:after {
			left: 30upx;
		}

		&.m-t {
			margin-top: 16upx;
		}

		.cell-more {
			align-self: baseline;
			font-size: $font-lg;
			color: $font-color-light;
			margin-left: 10upx;
		}

		.cell-tit {
			flex: 1;
			font-size: $font-base + 2upx;
			color: $font-color-dark;
			margin-right: 10upx;
		}

		.cell-tip {
			font-size: $font-base;
			color: $font-color-light;
		}

		switch {
			transform: translateX(16upx) scale(0.84);
		}
	}
</style>
